import Link from 'next/link'; import { notFound, redirect } from 'next/navigation'; import { getCustomerUser } from '@/app/lib/lumen-auth'; import { commerceDb } from '@/app/lib/commerce-db'; import { displayOrderId } from '@/app/lib/orders'; import { FramedPreview } from '@/app/components/FramedPreview'; import type { FrameId } from '@/app/data/frames'; import type { ProductId, Orientation } from '@/app/lib/pricing'; import { ApproveForm } from './form'; import { OrderConversation } from '@/app/components/OrderConversation'; import { CustomerOrderMessageForm } from '@/app/components/CustomerOrderMessageForm'; import { orderConversation, STUDIO_MESSAGE_STATUSES } from '@/app/lib/order-messages'; export const dynamic = 'force-dynamic'; export default async function ApprovePage( { params }: { params: Promise<{ id: string }> }, ) { const { id } = await params; const user = await getCustomerUser(); if (!user) redirect(`/login?next=/orders/${id}/approve`); const admin = commerceDb(); const { data: order } = await admin .from('orders') .select('id, user_id, status, price_cents, current_generation_id, config, revision_note, updated_at') .eq('id', id) .single(); if (!order) notFound(); if (order.user_id !== user.id) notFound(); const cfg = (order.config ?? {}) as { productId?: ProductId; size?: string; orientation?: Orientation; frame?: string; matteId?: string | null; proofIsRevision?: boolean; }; let proofUrl: string | null = null; if (order.current_generation_id) { const { data: gen } = await admin .from('generations') .select('clean_url') .eq('id', order.current_generation_id) .single(); proofUrl = gen?.clean_url ?? null; } const canApprove = order.status === 'awaiting_approval' && !!proofUrl; const messages = orderConversation(order.config, order.revision_note, order.updated_at); const canMessage = STUDIO_MESSAGE_STATUSES.includes(order.status); return (
← Order detail

{displayOrderId(order.id)} · {cfg.proofIsRevision ? 'review your revised proof' : 'review your proof'}

{proofUrl ? (

Shown here in your chosen frame & size, exactly as it will be printed.

) : (

No proof ready yet. We’ll email you when your portrait is ready to review.

)} {(messages.length > 0 || canMessage) && (
{canMessage && }
)} {canApprove ? ( ) : (

{order.status === 'awaiting_approval' ? 'Loading proof…' : order.status === 'revision_requested' ? 'Approval is paused. We’ll email you when an updated proof is ready.' : 'There is no proof awaiting approval.'}

)}
); }